package org.tis.tools.abf.module.ac.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.ac.controller.request.AcOperatorShortcutRequest;
import org.tis.tools.abf.module.ac.entity.AcOperatorShortcut;
import org.tis.tools.abf.module.ac.service.IAcOperatorShortcutService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.enums.OperateType;
import org.tis.tools.starter.operatelog.annotation.OperateLog;

import javax.validation.constraints.NotBlank;

/**
 * acOperatorShortcut的Controller类
 *  操作员快捷菜单
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@RestController
@RequestMapping("/acOperatorShortcut")
@Validated
@Slf4j
public class AcOperatorShortcutController extends BaseController<AcOperatorShortcut>  {

    @Autowired
    private IAcOperatorShortcutService acOperatorShortcutService;


    @ApiOperation(value = "新增操作员快捷菜单",notes = "传入AcOperatorShortcutRequest类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增操作员快捷菜单")
    @PostMapping
    public ResultVO add(@RequestBody @Validated @ApiParam(value = "AcOperatorShortcutRequest",name =
            "需要传入的AcOperatorShortcutRequest类", required = true) AcOperatorShortcutRequest acOperatorShortcutRequest) {
        acOperatorShortcutService.add(acOperatorShortcutRequest);
        return ResultVO.success("新增成功！");
    }


    @ApiOperation(value = "修改操作员快捷菜单",notes = "传入AcOperatorShortcutRequest类作为参数")
    @OperateLog(type = OperateType.UPDATE,desc = "修改操作员快捷菜单")
    @PutMapping
    public ResultVO update(@RequestBody @Validated @ApiParam(value = "AcOperatorShortcutRequest",name =
            "需要传入的AcOperatorShortcutRequest类", required = true) AcOperatorShortcutRequest acOperatorShortcutRequest) {
        AcOperatorShortcut acOperatorShortcut = acOperatorShortcutService.selectById(acOperatorShortcutRequest.getGuid());
        if (acOperatorShortcut == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorShortcut = acOperatorShortcutService.change(acOperatorShortcutRequest);
        return ResultVO.success("修改成功！",acOperatorShortcut);
    }


    @ApiOperation(value = "删除操作员快捷菜单",notes = "传入操作员呢快捷菜单GUID作为参数")
    @OperateLog(type = OperateType.DELETE,desc = "删除操作员快捷菜单")
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员呢快捷菜单的GUID", required = true) String id) {
        AcOperatorShortcut acOperatorShortcut = acOperatorShortcutService.selectById(id);
        if (acOperatorShortcut == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorShortcutService.deleteById(id);
        return ResultVO.success("删除成功");
    }


    @ApiOperation(value = "根据id查询操作员快捷菜单",notes = "传入操作员呢快捷菜单GUID作为参数")
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员呢快捷菜单的GUID", required = true) String id) {
        AcOperatorShortcut acOperatorShortcut = acOperatorShortcutService.selectById(id);
        if (acOperatorShortcut == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", acOperatorShortcut);
    }


    @ApiOperation(value = "列表查询",notes = "传入分页信息作为参数")
    @PostMapping("/list")
    public ResultVO list(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息(page)", required = true)
                                     SmartPage<AcOperatorShortcut> page) {
        return  ResultVO.success("查询成功", acOperatorShortcutService.selectPage(page.getPageObj(), page.getConditionWrapper()));
    }


    @ApiOperation(value = "根据操作员id查询列表",notes = "传入分页信息和操作员GUID作为参数")
    @PostMapping("/queryByOperator/{id}")
    public ResultVO queryByOperator(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息(page)", required = true) SmartPage<AcOperatorShortcut> page,@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员的GUID", required = true) String id) {
        return  ResultVO.success("查询成功", acOperatorShortcutService.queryByOperator(page.getPageObj(), page.getConditionWrapper(),id));
    }
}

